﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using vkUpploaderLib;

namespace VKUpploaderTests
{
    
    
    /// <summary>
    ///This is a test class for AuthHelperTest and is intended
    ///to contain all AuthHelperTest Unit Tests
    ///</summary>
    [TestClass()]
    public class AuthHelperTest
    {
        /// <summary>
        ///A test for IsError
        ///</summary>
        [TestMethod()]
        public void IsErrorTest()
        {
            string url = "http://api.vkontakte.ru/blank.html#error=access_denied&error_reason=user_denied&error_description=User denied your request";
            bool expected = true; 
            bool actual;
            actual = AuthHelper_Accessor.IsError(url);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("access_denied", AuthHelper.Error);
            Assert.AreEqual("user_denied", AuthHelper.ErrorReason);
            Assert.AreEqual("User denied your request", AuthHelper.ErrorDescripton);
        }

        [TestMethod()]
        public void IsNotErrorTest()
        {
            string url =
                "http://api.vkontakte.ru/blank.html#access_token=7c202fa5325e76877ceb535e257c47ed99e7c587c590d8cd03a886af6c11c41&expires_in=86400&user_id=7938601";
            bool expected = false;
            bool actual;


            actual = AuthHelper_Accessor.IsError(url);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("7c202fa5325e76877ceb535e257c47ed99e7c587c590d8cd03a886af6c11c41", AuthHelper.Token);
            Assert.AreEqual("86400", AuthHelper.ExpiresIn);
            Assert.AreEqual("7938601", AuthHelper.UserID);
            DateTime min = DateTime.Now - new TimeSpan(0,0,1,0);
            Assert.IsTrue(AuthHelper.TokenObtained > min);
        }
    }
}
